package com.smsc.headend.task.engine.utils;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.smsc.headend.common.enums.BasicParameter;
import com.smsc.headend.module.data.enums.OperationName;
import com.smsc.headend.module.task.dto.AtomicTask;
import com.smsc.headend.module.task.dto.Task;

import java.util.Map;

/**
 * @author wxh
 * @date 2021/2/25 17:01
 */
public class StepKeyUtil {
    public static String getStepKey(AtomicTask atomicTask, Task task) {
        String key = "message";
        if (StrUtil.isNotEmpty(task.getParamJson())) {
            Map<String, Object> m = JSONUtil.toBean(task.getParamJson(), Map.class);
            key = m.get("seq") != null ? Convert.toStr(m.get("seq")) : key;
        }
        OperationName operationName = OperationName.forId(atomicTask.getOperationId());
        switch (operationName) {
            case GetDcuDeviceName:
                key = Convert.toStr(BasicParameter.DEVICE_NAME.getValue());
                break;
            case GetDcuCommunicationAddr:
                key = Convert.toStr(BasicParameter.COMMUNICATION.getValue());
                break;
            case GetDcuBasicComParam:
            case SetDcuBasicComParam:
                key = Convert.toStr(BasicParameter.BASIC_COMMUNICATION.getValue());
                break;
            case GetDcuGPRSParam:
            case SetDcuGPRSParam:
                key = Convert.toStr((BasicParameter.GPRS.getValue()));
                break;
            case GetDcuEthernetParam:
            case SetDcuEthernetParam:
                key = Convert.toStr((BasicParameter.ETHERNET.getValue()));
                break;
            case GetDcuClockOverThreshold:
            case SetDcuClockOverThreshold:
                key = Convert.toStr((BasicParameter.CLOCK_OVER.getValue()));
                break;
            case GetDcuMonthOverThreshold:
            case SetDcuMonthOverThreshold:
                key = Convert.toStr((BasicParameter.MONTH_OVER.getValue()));
                break;
            case GetDcuBroadcastTimeCheck:
            case SetDcuBroadcastTimeCheck:
                key = Convert.toStr((BasicParameter.BROADCAST.getValue()));
                break;
            case GetDcuSignalStrength:
                key = Convert.toStr((BasicParameter.SIGNAL_STRENGTH.getValue()));
                break;
            case GetDcuLpDensity:
                key = Convert.toStr((BasicParameter.LOAD_PROFILE.getValue()));
                break;
            case FtpParametersSet:
            case FtpParametersGet:
                key = Convert.toStr((BasicParameter.FTP_SETTING.getValue()));
                break;
            case SetNtpActivated:
            case SetNtpServerAddr:
            case SetNtpServerPort:
            case GetNtpActivated:
            case GetNtpServerAddr:
            case GetNtpServerPort:
                key = Convert.toStr((BasicParameter.NTP_SETTING.getValue()));
                break;
            case SetDcuReboot:
                key = OperationName.SetDcuReboot.getName();
                break;
            case GetGprsModemApn:
            case SetGprsModemApn:
                key = Convert.toStr(BasicParameter.GPRS_MODEM_SETUP.getValue());
                break;
            case GetDcuAutoConnect:
            case SetDcuAutoConnect:
                key = Convert.toStr(BasicParameter.AUTO_CONNECT.getValue());
                break;
            case SetHeartBeatCycle:
            case GetHeartBeatCycle:
                key = Convert.toStr(BasicParameter.HEART_BEAT.getValue());
                break;
            case GetAutoRegisterMode:
            case SetAutoRegisterMode:
                key = Convert.toStr(BasicParameter.AUTO_REGISTER_MODE.getValue());
                break;
            case GetRefreshMeterStatus:
            case SetRefreshMeterStatus:
                key = Convert.toStr(BasicParameter.REFRESH_METER_STATUS.getValue());
                break;
            case GetNetworkOnlineMeterList:
                key = Convert.toStr(BasicParameter.NETWORK_ONLINE_METER_LIST.getValue());
                break;
            case GetNetWorkTopologyInformation:
                key = Convert.toStr(BasicParameter.NETWORK_TOPOLOGY_INFORMATION.getValue());
                break;
            case SetDcuPushStatus:
            case GetDcuPushStatus:
                key = Convert.toStr(BasicParameter.PUSH_STATUS.getValue());
                break;
        }

        return key;
    }
}
